/*
 * FGame.h
 *
 *  Created on : 12/04/2011
 *      Authors: Arthur
 *               Rafael
 *               Roberto
 *               Rubean
 */
#ifndef FGAME_H_
#define FGAME_H_

#include <FBase.h>
#include <FUi.h>
#include <FApp.h>
#include <FMedia.h>
#include <FSystem.h>

#include "GPlayer.h"
#include "GSymbol.h"

#define MAX_PLAYERS 2

using namespace Osp::Graphics;
using namespace Osp::Base;
using namespace Osp::Media;
using namespace Osp::Base::Collection;


class FGame :
	public Osp::Ui::Controls::Form,
	public Osp::Ui::IActionEventListener,
	public Osp::Ui::ITouchEventListener,
	public Osp::Base::Runtime::ITimerEventListener
{

public  :
	FGame();
	virtual ~FGame();
	bool   Initialize();
	result OnInitializing(void);
	result OnTerminating(void);

private :
  virtual void   OnActionPerformed (const Osp::Ui::Control &source, int actionId);
  virtual result OnDraw(void);

private :
  void   ConfigPlayers(void);
  result DrawGameView(void);
  void   DrawSymbol(Rectangle rect, String pathImg, bool onShow = false);
  bool   HasWinner(Point &point1, Point &point2);
  void	 RequestNewGame(String message);
  void   SetFormBackground();
  void   RedrawGame(bool onShow = false);
  void   SetCurrentPlayer(bool onShow = false);
  void   Scoreboard(bool onShow = false);

private :
  static const int	         __ID_BTN_BACK	=	100;
  Osp::Ui::Controls::Button* __pBtnBack;
  Canvas*                    __pCanvas;
  Osp::Base::Runtime::Timer  __timer;

  GPlayer    __players[2];
  GSymbol    __matriz[3][3];
  int        __indexPlayer;
  bool       __hasWinner;
  int        __countTies;
  ArrayList* __pListPlays;
  GPlayer*   __pCurrentPlayer;

public :
  virtual void OnTouchDoublePressed(const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const Osp::Ui::TouchEventInfo &touchInfo);
  virtual void OnTouchFocusIn(const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const Osp::Ui::TouchEventInfo &touchInfo);
  virtual void OnTouchFocusOut(const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const Osp::Ui::TouchEventInfo &touchInfo);
  virtual void OnTouchLongPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const Osp::Ui::TouchEventInfo &touchInfo);
  virtual void OnTouchMoved(const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const Osp::Ui::TouchEventInfo &touchInfo);
  virtual void OnTouchPressed(const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const Osp::Ui::TouchEventInfo &touchInfo);
  virtual void OnTouchReleased(const Osp::Ui::Control &source, const Osp::Graphics::Point &currentPosition, const Osp::Ui::TouchEventInfo &touchInfo);
  virtual void OnTimerExpired(Osp::Base::Runtime::Timer& timer);

};

#endif /* FGAME_H_ */
